import request from './request';

enum api {
	getUserPoster = 'Api/getUserPoster', // 获取用户信息
	getWxConfig = 'Api/getWxConfig', // 获取wxApi配置
	uploadImage = 'Api/uploadImage', // 上传图片
	deleteImage = 'Api/deleteImage', // 删除图片
	registerUser = 'Api/registerUser', // 注册用户
	memberInfo = 'Api/getMemberInfo', // 获取用户信息
	editMemberInfo = 'Api/editMemberInfo', // 修改用户信息
	opendIdByCode = 'WxStore/getOpendIdByCode', // 根据code获取用户信息
	globalConfigValue = 'Api/getGlobalConfigValue', // 获取配置参数
	addUser = 'WxStore/addUser', // 添加微信用户信息
	editUser = 'WxStore/editUser', // 修改微信用户信息
	updateUserAvatar = 'WxStore/updateUserAvatar', // 修改微信用户信息
	getAddressByGPS = 'Api/getAddressByGPS', // 解析地址
	bindUserRelate = 'WxStore/bindUserRelate', // 绑定用户关系
	wxPay = '../../extend/pay/request/wxPay.php', // 一元支付订单
	wxRedMotherPay = '../../extend/pay/request/wxRedMotherPay.php', // 红娘认证订单支付
	wxVipAuthPay = '../../extend/pay/request/wxVipAuthPay.php', // vip认证订单支付
	wxVipPay = '../../extend/pay/request/wxVipPay.php' // vip租赁订单支付
}

export function wxVipPay(oid: number) {
	return request.get({ url: api.wxVipPay, params: { oid } });
}

export function wxVipAuthPay(oid: number) {
	return request.get({ url: api.wxVipAuthPay, params: { oid } });
}

export function wxRedMotherPay(oid: number) {
	return request.get({ url: api.wxRedMotherPay, params: { oid } });
}

export function wxPay(oid: number) {
	return request.get({ url: api.wxPay, params: { oid } });
}

export function bindUserRelate(open_id: string, parent_id: number | string) {
	return request.post({ url: api.bindUserRelate, data: { open_id, parent_id } });
}

export function getAddressByGPS(lat: number, lng: number) {
	return request.get({ url: api.getAddressByGPS, params: { lat, lng } });
}

export function addUser(data: object) {
	return request.post({ url: api.addUser, data });
}

export function editUser(data: object) {
	return request.post({ url: api.editUser, data });
}

export function updateUserAvatar(data: object) {
	return request.post({ url: api.updateUserAvatar, data });
}

export function globalConfigValue(key: string) {
	return request.get({ url: api.globalConfigValue, params: { key } });
}

export function opendIdByCode(code: string) {
	return request.get({ url: api.opendIdByCode, params: { code } });
}

export function editMemberInfo(data: object) {
	return request.post({ url: api.editMemberInfo, data });
}

export function memberInfo(user_id: string | number,share_user_id:string | number = 0,uid:string | number = 0) {
	return request.get({ url: api.memberInfo, params: { user_id , share_user_id , uid} });
}

export function registerUser(data: object) {
	return request.post({ url: api.registerUser, data });
}

export function deleteImage(url: string) {
	return request.post({ url: api.deleteImage, data: { url } });
}

export function getUserPoster(user_id: string | number) {
	return request.post({ url: api.getUserPoster, data: { user_id } });
}

export function uploadImage(file: any) {
	return request.post({
		url: api.uploadImage,
		data: { file },
		headers: { 'Content-Type': 'multipart/form-data' }
	});
}

export function getWxConfig() {
	let url = window.location.href.split('#')[0]
	console.log('url',url);
	// return request.post({ url: api.getWxConfig, data: { url: window.location.href } });
	return request.post({ url: api.getWxConfig, data: { url: url } });
}
